package com.info.zhiduoduo.repository.mapper.entrustmentproject;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Condition;
import com.info.zhiduoduo.repository.dto.crowdsource.ExportProjectAcceptanceDto;
import com.info.zhiduoduo.repository.dto.crowdsource.ExportProjectAcceptanceItemDto;
import com.info.zhiduoduo.repository.dto.entrustmentproject.*;
import com.info.zhiduoduo.repository.dto.project.SameProjectDto;
import com.info.zhiduoduo.repository.entity.entrustmentproject.EntrustmentProjectItem;
import com.info.zhiduoduo.repository.entity.invoice.Invoice;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author bob
 * @since 2021-07-10
 */
public interface EntrustmentProjectItemMapper extends BaseMapper<EntrustmentProjectItem> {

	default List<EntrustmentProjectItem> listItems(int importId) {
		return new EntrustmentProjectItem().selectList(Condition.create().eq("import_id", importId));
	}

	default int deleteByImportId(Integer importId) {
		return delete(Condition.create().eq("import_id", importId));
	}

	@Select(" select epi.*,map.name as principalName,pc.projectcategory,maao.receipt_downloaded,IF(ISNULL(m.openid) or m.openid ='' ,0,1)as activeRegister " +
			" from zdd_entrustment_project_item epi " +
			" join zdd_company c on c.compid = epi.compid " +
			" left join zdd_maker_alipay_principal map on map.id = epi.principal_id " +
			" left join zdd_maker_account ma on ma.userid = epi.entrustee_id " +
			" left join zdd_maker_studio ms on ms.userid = epi.entrustee_id " +
			" left join zdd_maker m on m.userid = epi.entrustee_id " +
			" left join zdd_system_projectcategory pc on pc.projectcategoryid = epi.categoryid " +
			" left join zdd_maker_alipay_account_order maao on maao.project_id = epi.id and maao.state = 2 " +
			" where epi.import_id = #{importId} " +
			" order by epi.id ")
	List<EntrustmentProjectItemDto> listByImportId(int importId);

	@Select(" select epi.*,map.name as principalName,pc.projectcategory,maao.receipt_downloaded " +
			" from zdd_entrustment_project_item epi " +
			" join zdd_company c on c.compid = epi.compid " +
			" left join zdd_maker_alipay_principal map on map.id = epi.principal_id " +
			" left join zdd_maker_account ma on ma.userid = epi.entrustee_id " +
			" left join zdd_maker_studio ms on ms.userid = epi.entrustee_id " +
			" left join zdd_system_projectcategory pc on pc.projectcategoryid = epi.categoryid " +
			" left join zdd_maker_alipay_account_order maao on maao.project_id = epi.id and maao.state = 2 " +
			" where epi.compid = #{compid} " +
			" order by epi.id ")
	List<EntrustmentProjectItemDto> listByCompid(int compid);

	// 企业名,项目名,付款方姓名,收款人姓名,手机号,收款账号
	@Select(" select epi.*,map.name as principalName,pc.projectcategory,maao.receipt_downloaded,IF(ISNULL(m.openid) or m.openid ='' ,0,1)as activeRegister," +
			" ep.party_id,ep.pay_id,pay.pay_name " +
			" from zdd_entrustment_project_item epi " +
			" join zdd_entrustment_project ep on epi.import_id = ep.id " +
			" join zdd_company c on c.compid = epi.compid " +
			" left join zdd_maker_alipay_principal map on map.id = epi.principal_id " +
			" left join zdd_payment pay on pay.id = ep.pay_id " +
			" left join zdd_system_projectcategory pc on pc.projectcategoryid = epi.categoryid " +
			" left join zdd_maker_account ma on ma.userid = epi.entrustee_id " +
			" left join zdd_maker_studio ms on ms.userid = epi.entrustee_id " +
			" left join zdd_maker m on m.userid = epi.entrustee_id " +
			" left join zdd_maker_alipay_account_order maao on maao.project_id = epi.id and maao.state = 2 " +
			" where if(#{importId} = 0, 1=1, epi.import_id = #{importId}) " +
			" and CONCAT(epi.compname, epi.name, ifnull(epi.entrustee_name,''), ifnull(epi.entrustee_studio, ''), " +
			" epi.payee_name,epi.account_no) like '%${name}%' " +
			" and if(#{state}=0, 1=1, epi.state = #{state}) " +
			" and if(isnull(#{from}), 1=1, epi.createtime >= #{from})" +
			" and if(isnull(#{to}), 1=1, epi.createtime <= #{to})" +
			" order by epi.state desc, epi.id ")
	List<EntrustmentProjectItemDto> list(int importId, String name, Date from, Date to, int state);

	@Select(" select IFNULL(SUM(epi.project_amount), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where epi.entrustee_id = #{userid} " +
			" and epi.id != #{itemId} " +
			" AND epi.state in(${states}) " +
			" AND if(#{projectType}=0, 1=1, epi.project_type = #{projectType}) " +
			" AND if(#{invoiceType}=0, 1=1, epi.invoice_type = #{invoiceType}) " +
			" and IF(#{year}=0, YEAR(epi.createtime) = YEAR(NOW()), YEAR(epi.createtime) = #{year}) " +
			" and IF(#{month}=0, MONTH(epi.createtime) = MONTH(NOW()), MONTH(epi.createtime) = #{month} )")
	BigDecimal sumUserMonthTotalProjectAmountByStates(int userid, int itemId, String states, int projectType, int invoiceType, int year, int month);

	@Select(" select IFNULL(SUM(epi.project_amount), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where IF(#{userid}=0, 1=1, epi.entrustee_id = #{userid}) " +
			" AND epi.state in(${states}) " +
			" AND epi.project_type in (5,6) " +
			" and IF(#{year}=0, YEAR(epi.createtime) = YEAR(NOW()), YEAR(epi.createtime) = #{year}) " +
			" and IF(#{month}=0, MONTH(epi.createtime) = MONTH(NOW()), MONTH(epi.createtime) = #{month} )")
	BigDecimal sumUserMonthTotalEntrustProjectAmountByStates(int userid, String states, int year, int month);

	@Select(" select IFNULL(SUM(epi.project_amount), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where IF(#{userid}=0, 1=1, epi.entrustee_id = #{userid}) " +
			" AND epi.state in(${states}) " +
			" AND epi.project_type in (5,6) " +
			" and IF(#{year}=0, YEAR(epi.createtime) = YEAR(NOW()), YEAR(epi.createtime) = #{year})")
	BigDecimal sumUserYearTotalEntrustProjectAmountByStates(int userid, String states, int year);

	@Select(" select IFNULL(SUM(epi.project_amount), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where IF(#{userid}=0, 1=1, epi.entrustee_id = #{userid}) " +
			" AND epi.state in(${states}) " +
			" AND epi.project_type in (5,6) " +
			" and epi.createtime >= DATE_SUB(DATE_FORMAT(CURRENT_DATE(),'%y-%m-01'), INTERVAL 11 MONTH)")
	BigDecimal sumUserTwelveMonthTotalEntrustProjectAmountByStates(int userid, String states);

	@Select(" select IFNULL(SUM(epi.project_amount), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where IF(#{userid}=0, 1=1, epi.entrustee_id = #{userid}) " +
			" AND epi.state in(${states}) " +
			" AND epi.project_type in (7,8) " +
			" and IF(#{year}=0, YEAR(epi.createtime) = YEAR(NOW()), YEAR(epi.createtime) = #{year}) " +
			" and IF(#{month}=0, MONTH(epi.createtime) = MONTH(NOW()), MONTH(epi.createtime) = #{month} )")
	BigDecimal sumUserMonthTotalMakerGrouponProjectAmountByStates(int userid, String states, int year, int month);

	@Select(" select IFNULL(SUM(epi.project_amount), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where IF(#{userid}=0, 1=1, epi.entrustee_id = #{userid}) " +
			" AND epi.state in(${states}) " +
			" AND epi.project_type in (7,8) " +
			" and IF(#{year}=0, YEAR(epi.createtime) = YEAR(NOW()), YEAR(epi.createtime) = #{year})")
	BigDecimal sumUserYearTotalMakerGrouponProjectAmountByStates(int userid, String states, int year);

	@Select(" select IFNULL(SUM(epi.tax_inclusive_amount), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where IF(#{userid}=0, 1=1, epi.entrustee_id = #{userid}) " +
			" and epi.id != #{itemId} " +
			" AND epi.state in(${states}) " +
			" AND if(#{invoiceType}=0, 1=1, epi.invoice_type = #{invoiceType}) " +
			" and IF(#{year}=0, YEAR(epi.createtime) = YEAR(NOW()), YEAR(epi.createtime) = #{year}) " +
			" and IF(#{month}=0, MONTH(epi.createtime) = MONTH(NOW()), MONTH(epi.createtime) = #{month} )")
	BigDecimal sumUserMonthTotalAmountByStates(int userid, int itemId, String states, int invoiceType, int year, int month);

	@Select(" select IFNULL(SUM(epi.tax_inclusive_amount), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where IF(#{userid}=0, 1=1, epi.entrustee_id = #{userid}) " +
			" and epi.id != #{itemId} " +
			" AND epi.state in(${states}) " +
			" AND if(#{invoiceType}=0, 1=1, epi.invoice_type = #{invoiceType}) " +
			" and IF(#{year}=0, YEAR(epi.createtime) = YEAR(NOW()), YEAR(epi.createtime) = #{year}) " +
			" and IF(#{quarter}=0, QUARTER(epi.createtime) = QUARTER(NOW()),QUARTER(epi.createtime) = #{quarter} )")
	BigDecimal sumUserQuarterTotalAmountByStates(int userid, int itemId, String states, int invoiceType, int year, int quarter);

	@Select(" select IFNULL(SUM(epi.tax_inclusive_amount), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where epi.entrustee_id = #{userid} " +
			" and epi.id != #{itemId} " +
			" AND epi.state in(${states}) " +
			" AND epi.project_type in(${projectTypes}) " +
			" AND epi.invoice_type = 1 " +
			" and IF(#{year}=0, YEAR(epi.createtime) = YEAR(NOW()), YEAR(epi.createtime) = #{year}) " +
			" and IF(#{quarter}=0, QUARTER(epi.createtime) = QUARTER(NOW()),QUARTER(epi.createtime) = #{quarter} )")
	BigDecimal sumUserQuarterGenTotalAmountByProjectTypeAndStates(int userid, int itemId, String projectTypes, String states, int year,
	                                                              int quarter);

	@Select(" select IFNULL(SUM(epi.tax_inclusive_amount), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where IF(#{userid}=0, 1=1, epi.entrustee_id = #{userid}) " +
			" and epi.id != #{itemId} " +
			" AND epi.state in(${states}) " +
			" AND if(#{invoiceType}=0, 1=1, epi.invoice_type = #{invoiceType}) " +
			" and IF(#{year}=0, YEAR(epi.createtime) = YEAR(NOW()), YEAR(epi.createtime) = #{year})")
	BigDecimal sumUserYearTotalAmountByStates(int userid, int itemId, String states, int invoiceType, int year);

	@Select(" select IFNULL(SUM(epi.tax_inclusive_amount), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where epi.entrustee_id = #{userid} " +
			" and epi.id != #{itemId} " +
			" AND epi.state in(${states}) " +
			" and epi.createtime >= DATE_SUB(DATE_FORMAT(CURRENT_DATE(),'%y-%m-01'), INTERVAL 11 MONTH)")
	BigDecimal sumUserTwelveMonthTotalAmountByStates(int userid, int itemId, String states);

	@Select(" select IFNULL(SUM(epi.tax_inclusive_amount), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where epi.entrustee_id in (${userIds}) " +
			" AND epi.state in(${states}) " +
			" AND epi.id != #{projectid} " +
			" and IF(#{timeType} = 1 ,YEAR(epi.createtime) = YEAR(NOW()), " +
			"     epi.createtime >= DATE_SUB(DATE_FORMAT(CURRENT_DATE(),'%y-%m-01'), INTERVAL 11 MONTH))")
	BigDecimal getEntrustAmountByUserIds(String userIds, int projectid, String states, int timeType);

	@Update(" update zdd_entrustment_project_item set entrust_state = #{state} " +
			" where transfer_no = #{orderNo} " +
			" and entrustee_id = #{entrusteeId} ")
	boolean updateEntrustState(String orderNo, Integer entrusteeId, int state);

	@Select(" select epi.id as projectid,epi.name as projectname,epi.tax_inclusive_amount as invoiceAmount," +
			" epi.invoice_type as invoicetype,epi.invoice_content as content,epi.finish_time as projectfinishtime," +
			" us.userid,epi.entrustee_studio as username,us.creditcode as userTaxno,us.addr as userAddress,m.phone as userTelephone," +
			" ub.bankname as userAcctbank,ub.acctno as userAcctno," +
			" c.compid,epi.compname,c.creditcode as compTaxno,c.acctbank as compAcctbank," +
			" c.acctno as compAcctno,c.telephone as compTelephone,IFNULL(c.invoiceaddress,c.contactaddress) as compAddress," +
			" c.compemail as email,c.contactname,c.contactphone " +
			" from zdd_entrustment_project_item epi " +
			" join zdd_maker_studio us on us.userid = epi.entrustee_id " +
			" join zdd_maker m on m.userid = epi.entrustee_id " +
			" join zdd_maker_bankcard ub on ub.userid = us.userid and ub.state = 1 and ub.accttype = 1 " +
			" join zdd_company c on c.compid = epi.compid " +
			" where epi.id = #{projectid} ")
	Invoice getPendingInvoiceDetail(int projectid);

	@Select(" select IFNULL(SUM(epi.tax_fee), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where epi.entrustee_id = #{userid} " +
			" and epi.state in(${states}) " +
			" and epi.project_type in(7) " +
			" and epi.id != #{itemId} " +
			" and YEAR(epi.createtime) = YEAR(NOW())")
	BigDecimal sumUserYearZhiduoduoTaxFeeByStates(int userid, int itemId, String states);

	@Select(" select IFNULL(SUM(epi.tax_fee), 0) " +
			" from zdd_entrustment_project_item epi " +
			" where epi.entrustee_id = #{userid} " +
			" and epi.state in(${states})" +
			" and epi.id != #{itemId} " +
			" AND if(#{projectType}=0, 1=1, epi.project_type = #{projectType}) " +
			" and YEAR(epi.createtime) = YEAR(NOW()) " +
			" and MONTH(epi.createtime) = MONTH(NOW()) ")
	BigDecimal sumUserMonthTaxFeeByStates(int userid, int itemId, String states, int projectType);

	@Select(" delete epi,ep  from zdd_entrustment_project_item epi " +
			" left join zdd_entrustment_project ep  on epi.import_id = ep.id " +
			" where epi.entrustee_id = #{userid} " +
			" and YEAR(epi.createtime) = YEAR(NOW())")
	Integer delYearProjectData(int userid);

	@Select(" delete epi,ep from zdd_entrustment_project_item epi " +
			" left join zdd_entrustment_project ep  on epi.import_id = ep.id " +
			" where epi.entrustee_id = #{userid} " +
			" and YEAR(epi.createtime) = YEAR(NOW())" +
			" and QUARTER(epi.createtime) = #{quarter}")
	Integer delQuarterProjectData(int userid, int quarter);

	@Select(" select IFNULL(SUM(tax_inclusive_amount), 0) " +
			" from zdd_entrustment_project_item " +
			" where compid in(${compids}) " +
			" and DATE(transfer_time) between DATE(#{from}) and DATE(#{to}) ")
	BigDecimal getTotalAmountByCompids(String compids, Date from, Date to);

	@Select(" select IFNULL(SUM(tax_inclusive_amount), 0) " +
			" from zdd_entrustment_project_item " +
			" where entrustee_id = #{userid} " +
			" and DATE(transfer_time) between DATE(#{from}) and DATE(#{to}) ")
	BigDecimal getTotalAmountByUserid(int userid, Date from, Date to);

	@Select(" SELECT pro.id,item.compid,item.entrustee_id as userid,item.entrustee_name as realname,item.entrustee_studio as username,item.invoice_content," +
			" ma.opening_location as openingLocation,ms.invoicescope " +
			" FROM zdd_entrustment_project_item item " +
			" RIGHT JOIN (SELECT MAX(id) AS id FROM zdd_entrustment_project WHERE compid = #{compid} and state >= 3) pro " +
			" ON pro.id = item.import_id " +
			" JOIN zdd_maker m on m.userid = item.entrustee_id and m.state != 4 " +
			" JOIN zdd_maker_account ma on ma.userid = m.userid " +
			" JOIN zdd_maker_studio ms on ms.userid = ma.userid" +
			" GROUP BY item.entrustee_id ")
	List<EntrustmentProjectMakerDto> queryLastProjectMaker(Integer compid);

	@Select(" SELECT pro.id,pro.imported_amount,item.import_id,item.compid,item.compname,sum(item.amount) as amount,sum(item.tax_inclusive_amount) as taxInclusiveAmount," +
			" item.invoice_content,item.entrustee_id,item.entrustee_name,item.entrustee_studio,pro.createtime " +
			" FROM zdd_entrustment_project_item item " +
			" left join zdd_entrustment_project pro on item.import_id = pro.id " +
			" where pro.compid = #{compid} " +
			" and item.state != 1 and pro.state != 1 " +
			" GROUP BY item.entrustee_id,item.invoice_content ")
	List<EntrustmentProjectCompanyDto> queryProjectListByCompId(Integer importId);

	@Select(" select IFNULL(SUM(tax_inclusive_amount), 0) " +
			" from zdd_entrustment_project_item " +
			" where entrustee_id = #{userid} " +
			" and state in (${states}) " +
			" and DATE(createtime) between DATE(#{from}) and DATE(#{to}) ")
	BigDecimal getTotalEntrustAmountByUserid(int userid, Date from, Date to,String states);

	@Select(" select epi.import_id,epi.entrustee_id,epi.entrustee_name,epi.entrustee_studio,epi.name,epi.content,epi.project_type,epi.createtime, " +
			" CONCAT('WT',DATE_FORMAT(epi.createtime,'%Y%m%d'),epi.import_id,epi.entrustee_id) as contractNo,pro.party_id," +
			" case epi.project_type when 6 then map.name when 8 then map.name else epi.compname end as compname," +
			" ccp.company_name as partyName," +
			" round(sum(case epi.project_type when 6 then epi.project_amount when 8 then epi.project_amount else epi.tax_inclusive_amount end),2) as projectAmount " +
			" from zdd_entrustment_project_item epi " +
			" left join zdd_entrustment_project pro on epi.import_id = pro.id " +
			" left join zdd_maker_alipay_principal map on map.id = epi.principal_id " +
			" left join zdd_crowdsource_company_party ccp on ccp.id = pro.party_id " +
			" where pro.state = 5 " +
			" and if(isnull(#{entrusteeId}), 1=1, epi.entrustee_id = #{entrusteeId}) " +
			" and pro.id = #{importId} " +
			" group by epi.import_id,epi.entrustee_id")
	List<ProjectEntrusteeInfoDto> getEntrustProjectContractInfo(Integer importId,Integer entrusteeId);

	// 获取企业的项目数据 selectType=1：15分钟内交易的数据 selectType=1：根据项目ID查询
	@Select("select epi.import_id as projectid,epi.crowdsourceid as userid,epi.crowdsource_name as realname,amount as projectAmount" +
			" from zdd_entrustment_project_item epi" +
			" join zdd_entrustment_project ep on epi.import_id = ep.id " +
			" where " +
			" if(#{selectType} = 1,epi.state in(${states}) and CURRENT_DATE() = DATE(epi.dispatch_time), epi.import_id in (${projectIds}) )")
	List<SameProjectDto> getTimeSlotProject(Integer selectType, String states, String projectIds);

	@Select(" SELECT pro.id,pro.imported_amount,item.import_id,item.compid,item.compname,sum(item.amount) as amount,sum(item.tax_inclusive_amount) as taxInclusiveAmount," +
			" item.invoice_content,item.entrustee_id,item.entrustee_name,item.entrustee_studio,pro.createtime " +
			" FROM zdd_entrustment_project_item item " +
			" left join zdd_entrustment_project pro on item.import_id = pro.id " +
			" where pro.compid = #{compid} " +
			" AND IF( #{year} > 0 , YEAR(pro.createtime ) = #{year} , 1 = 1) " +
			" AND IF( #{month} > 0 , MONTH(pro.createtime ) = #{month} , 1 = 1) " +
			" and item.state != 1 and pro.state != 1 " +
			" GROUP BY item.entrustee_id,item.invoice_content ")
	List<EntrustmentProjectCompanyDto> monthlyQueryCompanyHistoryProjects(@Param("compid") Integer compid,
																		  @Param("year") int year,
																		  @Param("month") int month);

	//查询委托 /创客团  生成合同需要的数据
	@Select("select epi.import_id as projectid,GROUP_CONCAT(epi.id) as itemIds,epi.name as projectname,epi.compid,epi.dispatch_time as publishTime," +
			" epi.entrustee_id as userid,epi.createtime as projectstart,epi.finish_time as projectfinish,epi.compname,  " +
			" epb.delivery_path,epi.entrustee_name as username,round(sum(epi.tax_inclusive_amount),2) as projectAmount  " +
			" FROM zdd_entrustment_project_item epi  " +
			" LEFT JOIN zdd_entrustment_project_block epb on epi.import_id = epb.project_id  " +
			" WHERE epi.state in(${states})  " +
			" AND epi.project_type in (5,7)  " +
			" AND IF(ISNULL(#{projectId}) or #{projectId} = '', 1=1, epi.import_id = #{projectId})  " +
			" AND IF(ISNULL(#{entrusteeId}) or #{entrusteeId} = '', 1=1, epi.entrustee_id = #{entrusteeId})  " +
			" AND IF(ISNULL(#{compid}) or #{compid} = 0, 1=1, epi.compid = #{compid})" +
			" GROUP BY epi.import_id,epi.entrustee_id ")
	List<ExportProjectAcceptanceDto> getZddProjectAcceptance(Integer compid, Integer projectId, Integer entrusteeId,String states);

	//查询委托智众包/创客团智众包 生成合同需要的数据
	@Select("select epi.import_id as projectid,GROUP_CONCAT(epi.id) as itemsIds,epi.name as projectname,epi.compid,epi.dispatch_time as publishTime,  " +
			" epi.entrustee_id as userid,epi.createtime as projectstart,epi.finish_time as projectfinish,epi.compname, ccp.company_name as partyname, " +
			" epb.delivery_path,epi.entrustee_name as username, round(sum(epi.project_amount),2) as projectAmount " +
			" FROM zdd_entrustment_project_item epi " +
			" LEFT JOIN zdd_entrustment_project ep on epi.import_id = ep.id " +
			" LEFT JOIN zdd_entrustment_project_block epb on epi.import_id = epb.project_id  " +
			" LEFT JOIN zdd_crowdsource_company_party ccp on ep.party_id = ccp.id   " +
			" WHERE epi.state in(${states}) " +
			" AND epi.project_type in (6,8)  " +
			" AND IF(ISNULL(#{projectId}) or #{projectId} = '', 1=1, epi.import_id = #{projectId})  " +
			" AND IF(ISNULL(#{entrusteeId}) or #{entrusteeId} = '', 1=1, epi.entrustee_id = #{entrusteeId})  " +
			" AND IF(ISNULL(#{compid}) or #{compid} = 0, 1=1, epi.compid = #{compid})  " +
			" GROUP BY epi.import_id,epi.entrustee_id    ")
	List<ExportProjectAcceptanceDto> getCroProjectAcceptance(Integer compid, Integer projectId, Integer entrusteeId, String states);

	@Select("SELECT item.entrustee_name as username,round(item.tax_inclusive_amount,2) as integratedTaxFee," +
			" round(item.project_amount,2) as projectAmount " +
			" from zdd_entrustment_project_item item " +
			" where item.import_id = #{projectid}")
	List<ExportProjectAcceptanceItemDto> getProjectAcceptanceItemList(Integer projectid);

	// 查询企业已完成超过5天未提交验收单的项目Id
	@Select(" SELECT epi.import_id,epi.entrustee_id " +
			" FROM zdd_entrustment_project_item epi  " +
			" LEFT JOIN zdd_entrustment_project ep on epi.import_id = ep.id" +
			" LEFT JOIN zdd_entrustment_project_block epb on epi.import_id = epb.project_id" +
			" WHERE epi.state in(3) " +
			" AND IF(#{projectType} = 0, epi.project_type in (7,8), epi.project_type = #{projectType}) " +
			" AND epb.delivery_path is null " +
			" AND IF(ISNULL(#{compid}) or #{compid} = 0, 1=1, epi.compid = #{compid})  " +
			" AND epi.finish_time <= DATE_SUB(CURRENT_DATE(),INTERVAL 5 DAY) " +
			" GROUP BY epi.import_id,epi.entrustee_id ")
	List<EntrustmentProjectItemReduceDto> getCompProjectDeliveryNum(@Param("compid") Integer compid, @Param("projectType") int projectType);

}
